package org.tigris.subversion.svnant.conditions;

import java.io.File;
import java.net.MalformedURLException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.tigris.subversion.svnant.SvnFacade;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.ISVNInfo;
import org.tigris.subversion.svnclientadapter.SVNClientException;
import org.tigris.subversion.svnclientadapter.SVNNodeKind;
import org.tigris.subversion.svnclientadapter.SVNRevision;
import org.tigris.subversion.svnclientadapter.SVNRevision.Number;
import org.tigris.subversion.svnclientadapter.SVNUrl;

public class Available extends SvnCondition
{
  private String target = null;
  private FileDir type = null;

  protected void preconditions()
    throws BuildException
  {
    if (this.target == null)
      throw new BuildException("Missing attribute 'target'.");
  }

  protected boolean internalEval()
  {
    ISVNClientAdapter localISVNClientAdapter = SvnFacade.getClientAdapter(this);
    ISVNInfo localISVNInfo = null;
    try
    {
      File localFile = new File(Project.translatePath(this.target));
      if (localFile.exists())
        localISVNInfo = localISVNClientAdapter.getInfo(localFile);
      else
        try
        {
          SVNUrl localSVNUrl = new SVNUrl(this.target);
          localISVNInfo = localISVNClientAdapter.getInfo(localSVNUrl);
        }
        catch (MalformedURLException localMalformedURLException)
        {
          throw new BuildException("The url '" + this.target + "' is not valid.", localMalformedURLException);
        }
    }
    catch (SVNClientException localSVNClientException)
    {
      return false;
    }
    if (null == localISVNInfo)
      return false;
    if ((localISVNInfo.getRevision() == null) || (SVNRevision.INVALID_REVISION.equals(localISVNInfo.getRevision())))
      return false;
    if (this.type != null)
    {
      if (this.type.isDir())
        return localISVNInfo.getNodeKind() == SVNNodeKind.DIR;
      return localISVNInfo.getNodeKind() == SVNNodeKind.FILE;
    }
    return true;
  }

  public void setTarget(String paramString)
  {
    this.target = paramString;
    if ((this.target != null) && (this.target.length() == 0))
      this.target = null;
  }

  public void setType(FileDir paramFileDir)
  {
    this.type = paramFileDir;
  }

  public static class FileDir extends EnumeratedAttribute
  {
    private static final String[] VALUES = { "file", "dir" };

    public String[] getValues()
    {
      return VALUES;
    }

    public boolean isDir()
    {
      return "dir".equalsIgnoreCase(getValue());
    }

    public boolean isFile()
    {
      return "file".equalsIgnoreCase(getValue());
    }
  }
}

/* Location:           C:\Users\Administrator\Desktop\svnant.jar
 * Qualified Name:     org.tigris.subversion.svnant.conditions.Available
 * JD-Core Version:    0.6.0
 */